package com.example.a2209_shop.fgViewModel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CateEntityResult
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CateViewModel:BaseViewModel() {
    //一二级分类的请求
    val cateSuccess = MutableLiveData<CateEntityResult>()
    val cateFail = MutableLiveData<String>()

    fun cate(){
        viewModelScope.launch {
            try {
                cateSuccess.value = apiServer.cate()
            }catch (e:Exception){
                cateFail.value = e.message
            }
        }
    }

    //三级商品列表的请求
    val goodsSuccess = MutableLiveData<GoodsEntityResult>()
    val goodsFail = MutableLiveData<String>()
    fun goods(categroy_id:Int,currentPage:Int,pageSize:Int){
        viewModelScope.launch {
            try {
                goodsSuccess.value = apiServer.goods(categroy_id,currentPage, pageSize)
            }catch (e:Exception){
                goodsFail.value = e.message
            }
        }
    }
}